
package com.qdu.servlet;

import com.qdu.entity.Admin;
import com.qdu.service.AdminService;
import com.qdu.service.impl.AdminServiceImpl;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.tomcat.jni.SSLContext;

/**
 *
 * @author 24959
 */
@WebServlet("/aa")
public class AddAdminServlet extends HttpServlet{

    AdminService adminService=new AdminServiceImpl();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        
        req.setCharacterEncoding("utf-8");
        int Ano = Integer.parseInt(req.getParameter("Ano")); 
        String Aname = req.getParameter("Aname");
        String Apwd = req.getParameter("Apwd");
        //获取管理员的信息，封装成一个Admin对象
        Admin newAdmin = new Admin(Ano,Aname,Apwd);
        //2. 执行业务逻辑
        //将新管理员插入数据库
        int rows=adminService.addNewAdmin(newAdmin);
        //3. 生成响应内容，这里直接返回了受影响的行数，用于判断是否插入成功  
        //resp.getWriter().println(rows); 
        if(rows==1){
            req.getRequestDispatcher("/addAdminsuccess.jsp").forward(req, resp);
        }else{
            req.getRequestDispatcher("/addAdmindefeat.jsp").forward(req, resp);
        }        
    }
    
}
